// pages/mine/order/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabindex: 0,
        tab: ["全部", "待付款", "待发货", "待收货", "售后"],
        orderlist: [{
                id: 1,
                storename: "中华山楂食品厂",
                status: "等待付款",
                product: [{
                        img: "/images/product1.png",
                        name: "一品轩皇家有机食用调和油有机食机用调和油",
                        sort: "无糖山楂",
                        weight: "80g",
                        price: "78.00",
                        num: 2
                    },
                    {
                        img: "/images/product1.png",
                        name: "一品轩皇家有机食用调和油有机食机用调和油",
                        sort: "无糖山楂",
                        weight: "80g",
                        price: "78.00",
                        num: 2
                    },
                ],
                totalprice: 0,
                totalnum: 0
            },
            {
                id: 2,
                storename: "中华山楂食品厂",
                status: "等待付款",
                product: [{
                        img: "/images/product1.png",
                        name: "一品轩皇家有机食用调和油有机食机用调和油",
                        sort: "无糖山楂",
                        weight: "80g",
                        price: "78.00",
                        num: 2
                    },
                    {
                        img: "/images/product1.png",
                        name: "一品轩皇家有机食用调和油有机食机用调和油",
                        sort: "无糖山楂",
                        weight: "80g",
                        price: "78.00",
                        num: 2
                    },
                ],
				totalprice: 0,
				totalnum: 0
            }
        ]
    },
    onLoad: function(options) {
		this.gettotal()
    },
    onReady: function() {

    },
    onShow: function() {

    },
    tabtap: function(e) {
        this.setData({
            tabindex: e.currentTarget.dataset.index
        })
    },
    gettotal() {
        var temp = this.data.orderlist
        for (var i = 0; i < temp.length; i++) {
            for (var j = 0; j < temp[i].product.length; j++) {
				temp[i].totalnum +=temp[i].product[j].num
				temp[i].totalprice += temp[i].product[j].num * temp[i].product[j].price
            }
        }
		
		this.setData({
			orderlist:temp
		})
    }
})